local qingjie = fk.CreateSkill {
  name = "xiaobai__qingjie"
}
Fk:loadTranslationTable {
  ["xiaobai__qingjie"] = "清节",
  [":xiaobai__qingjie"] = "当你不因使用或打出而失去牌后，若回合角色当前剩余使用【杀】次数为：0，你摸一张牌；大于0，令之-1。",
  ["@xiaobai__qingjie-phase"] = "清节",
}

qingjie:addEffect(fk.AfterCardsMove, {
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qingjie.name) and player.room.current then
      for _, move in ipairs(data) do
        if move.from == player and (move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResponse) then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local curPlayer = room.current
    local card = Fk:cloneCard("slash")
    local card_skill = card.skill
    local status_skills = room.status_skills[TargetModSkill] or Util.DummyTable
    for _, skill in ipairs(status_skills) do
      if skill:bypassTimesCheck(curPlayer, card_skill, Player.HistoryPhase, card, nil) then return true end
    end
    local limit = card_skill:getMaxUseTime(curPlayer, Player.HistoryPhase, card, nil)
    if limit and curPlayer.phase == Player.Play and curPlayer:usedCardTimes("slash", Player.HistoryPhase) < limit then
      event:setCostData(self, { anim_type = "control" })
    else
      event:setCostData(self, { anim_type = "drawcard" })
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local curPlayer = room.current
    local card = Fk:cloneCard("slash")
    local card_skill = card.skill
    local status_skills = room.status_skills[TargetModSkill] or Util.DummyTable
    for _, skill in ipairs(status_skills) do
      if skill:bypassTimesCheck(curPlayer, card_skill, Player.HistoryPhase, card, nil) then return true end
    end
    local limit = card_skill:getMaxUseTime(curPlayer, Player.HistoryPhase, card, nil)
    if limit and curPlayer.phase == Player.Play and curPlayer:usedCardTimes("slash", Player.HistoryPhase) < limit then
      local num = player:getMark("@xiaobai__qingjie-phase")
      room:setPlayerMark(curPlayer, "@xiaobai__qingjie-phase", num - 1)
    else
      player:drawCards(1, qingjie.name)
    end
  end,
})

qingjie:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope, card, to)
    if player:getMark("@xiaobai__qingjie-phase") ~= 0 and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:getMark("@xiaobai__qingjie-phase")
    end
  end
})

return qingjie
